023308
@@ -45,14 +45,14 @@
public SecureCmdDoAs(HiveConf conf) throws HiveException, IOException{
     // metastore tokens into a file
     String uname = UserGroupInformation.getLoginUser().getShortUserName();
     FileSystem fs = FileSystem.get(conf);
-    Token<?> fsToken = fs.getDelegationToken(uname);
+    Credentials cred = new Credentials();
+    // Use method addDelegationTokens instead of getDelegationToken to get all the tokens including KMS.
+    fs.addDelegationTokens(uname, cred);
 
     tokenFile = File.createTempFile("hive_hadoop_delegation_token", null);
     tokenPath = new Path(tokenFile.toURI());
 
     //write credential with token to file
-    Credentials cred = new Credentials();
-    cred.addToken(fsToken.getService(), fsToken);
     cred.writeTokenStorageFile(tokenPath, conf);
   }
 
